#include "YGDir.h"

namespace YoghurtGum
{

	Dir::Dir(const char* a_Path)
	{
		m_FolderFirst = m_FolderPrev = m_FolderCurr = NULL;
		m_FolderTotal = 0;

		size_t count = 0;
		const char* start = a_Path;
		const char* curr = a_Path;
		char path[256];

		for (size_t i = 0; i < strlen(a_Path); i++)
		{
			if (*curr == '\\' || *curr == '/')
			{
				strncpy(path, start, count);
				path[count] = 0;
				AddFolder(path);

				curr++;
				start = curr;
				count = 0;
			}
			else
			{
				count++;
				curr++;
			}
		}
		if (count > 0)
		{
			strncpy(path, start, count);
			path[count] = 0;
			AddFolder(path);
		}
	}

	Dir::~Dir()
	{

	}

	void Dir::AddFolder(const char* a_Path)
	{
		Log::GetSingleton().Print("Folder: '%s'", a_Path);

		if (!m_FolderFirst)
		{
			m_FolderFirst = new Folder;
			m_FolderCurr = m_FolderFirst;
			m_FolderPrev = NULL;
		}
		else
		{
			Folder* temp = new Folder;
			m_FolderCurr->down = temp;
			m_FolderCurr = temp;
		}

		strcpy(m_FolderCurr->name, a_Path);
		m_FolderCurr->up = m_FolderPrev;
		m_FolderCurr->down = NULL;

		m_FolderPrev = m_FolderCurr;
	}

}